Skip to content

feat: optimize project list external endpoint#7869

Merged
dheeru0198 merged 1 commit intopreviewfrom
fix-project-list-endpoint-optimize
Sep 29, 2025
Merged

feat: optimize project list external endpoint#7869
dheeru0198 merged 1 commit intopreviewfrom
fix-project-list-endpoint-optimize

Conversation

@sriramveeraghanta
Copy link
Copy Markdown
Member

@sriramveeraghanta sriramveeraghanta commented Sep 29, 2025

Description

  • Optimize external projects list endpoints

Type of Change

  • Improvement (change that would cause existing functionality to not work as expected)

Summary by CodeRabbit

  • Refactor
    • Optimized data fetching for project lists to reduce unnecessary preloading and improve responsiveness.
    • Users may notice faster loading times when browsing projects, with no changes to visible features or behavior.
    • The update streamlines server-side processing and can reduce server load during peak usage.
    • No action required from users or administrators.

Copilot AI review requested due to automatic review settings September 29, 2025 15:05
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Sep 29, 2025

Walkthrough

The queryset in ProjectListCreateAPIEndpoint.get_queryset was modified to reduce select_related preloading from multiple relations ("workspace", "workspace__owner", "default_assignee", "project_lead") to only "project_lead". No other logic or public interfaces were changed.

Changes

Cohort / File(s) Change summary
API queryset optimization
apps/api/plane/api/views/project.py
Narrowed ORM select_related from {"workspace", "workspace__owner", "default_assignee", "project_lead"} to {"project_lead"} within get_queryset; remaining annotations and filters unchanged.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant C as Client
    participant API as ProjectListCreateAPIEndpoint
    participant ORM as ORM/DB

    C->>API: GET /projects
    API->>ORM: Query Projects<br/>select_related("project_lead")
    Note right of ORM: Previously also selected<br/>"workspace", "workspace__owner",<br/>"default_assignee"
    ORM-->>API: Project rows + joined project_lead
    API-->>C: Response with projects
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • dheeru0198

Poem

I twitch my whiskers, hop with glee,
A slimmer query sets data free.
Less baggage on the fetch we tread,
Just project leads, not all the thread.
Thump-thump—cache it, keep it tight,
A nimble hop, performance light! 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description provides only a brief statement of intent and the change type but omits critical details required by the template, such as a comprehensive description of what was modified, the Test Scenarios section, any screenshots or media, and references to related issues or design documents. Please expand the Description section with a detailed explanation of the code changes, fill out the Test Scenarios section with the steps and outcomes of your verification, and include any relevant screenshots, media, or issue references to fully align with the repository’s PR template.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly describes the primary change by specifying an optimization of the project list external endpoint and is concise and free of extraneous details.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-project-list-endpoint-optimize

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR optimizes the external projects list endpoint by reducing the number of database joins in the project queryset. The change removes unnecessary select_related fields to improve query performance.

  • Removes unnecessary database joins from the project queryset
  • Maintains only the essential project_lead relationship
  • Improves performance for external project list endpoints

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread apps/api/plane/api/views/project.py
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9237f56 and f68c32b.

📒 Files selected for processing (1)
  • apps/api/plane/api/views/project.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Lint API
  • GitHub Check: Analyze (javascript)

| Q(network=2)
)
.select_related("workspace", "workspace__owner", "default_assignee", "project_lead")
.select_related("project_lead")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Reintroduce eager loading for workspace/default_assignee to avoid N+1 queries

With this change the list endpoint stops preloading workspace, workspace__owner, and default_assignee. Any client that uses the documented expand parameter (or the serializer’s default fields) now triggers one extra query per project for each of those relations, undoing the optimization we previously had. That’s a significant performance regression for a list API that can easily return dozens of projects. Please keep those relations in select_related (or replace them with an equivalent prefetch strategy) so the endpoint remains O(1) queries.

-            .select_related("project_lead")
+            .select_related("workspace", "workspace__owner", "default_assignee", "project_lead")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
.select_related("project_lead")
.select_related("workspace", "workspace__owner", "default_assignee", "project_lead")
🤖 Prompt for AI Agents
In apps/api/plane/api/views/project.py around line 82, the query no longer
eager-loads workspace, workspace__owner, and default_assignee which causes N+1
queries on the list endpoint; restore those relations to the queryset (e.g. add
them back into select_related or use an equivalent prefetch_related for
m2m/lookups) so the endpoint remains O(1) queries when returning many projects,
ensuring workspace, workspace__owner, and default_assignee are included in the
eager-loading set.

@dheeru0198 dheeru0198 merged commit ded3678 into preview Sep 29, 2025
9 checks passed
@dheeru0198 dheeru0198 deleted the fix-project-list-endpoint-optimize branch September 29, 2025 15:10
zy1000 pushed a commit to zy1000/plane that referenced this pull request Oct 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants